import type { MenuDataItem } from "@ant-design/pro-components";

import { RouteObject } from "../routes/interface";
import { MAIN_PRIMARY_COLOR } from "../enums";

/**
 * 把routers转换成menu数据
 * @param list
 */
export const getMenusData = (list: RouteObject[]): MenuDataItem[] => {
	return list?.reduce((res, item) => {
		if (item.meta?.title) {
			const menuItem: MenuDataItem = {
				path: item.path,
				name: item.meta?.title,
				icon: item.meta?.icon,
				key: item.meta?.key ?? `${Math.random()}`,
				children: item?.children ? getMenusData(item.children) : []
			};
			//@ts-ignore
			res.push(menuItem);
		}
		return res;
	}, []);
};

/**
 * proLayout的默认配置
 */
export const InitialSettings = {
	navTheme: "light",
	// 拂晓蓝
	colorPrimary: MAIN_PRIMARY_COLOR,
	layout: "mix",
	contentWidth: "Fluid",
	fixedHeader: false,
	fixSiderbar: true,
	colorWeak: false,
	title: "小程序后台管理",
	pwa: false
};
